package com.rskg.g_rskg.service;

import com.rskg.g_rskg.Mapper.EbookMapper;
import com.rskg.g_rskg.domin.Ebook;
import com.rskg.g_rskg.domin.EbookExample;
import com.rskg.g_rskg.resp.EbookResp;
import com.rskg.g_rskg.teq.EbookReq;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class EbookService {
    @Resource
//    @Autowired  这是sprintboot 带的，上面那个jdk带的
    private EbookMapper ebookMapper;
    public List<EbookResp> list(EbookReq Req) {
        EbookExample ebookExample = new EbookExample();
        ebookExample.createCriteria().andNameLike("%" + Req.getName() + "%");
        List<Ebook> ebooklist = ebookMapper.selectByExample(ebookExample);
        List<EbookResp> respList =new ArrayList<>();
        for (Ebook ebook : ebooklist) {
            EbookResp ebookResp = new EbookResp();
            ebookResp.setId(ebook.getId());
            ebookResp.setName(ebook.getName());
            ebookResp.setCategory1Id(ebook.getCategory1Id());
            ebookResp.setCategory2Id(ebook.getCategory2Id());
            ebookResp.setDescription(ebook.getDescription());
            ebookResp.setCover(ebook.getCover());
            respList.add(ebookResp);
        }
        return respList;
    }
}
